Welcome to JavaScript!

3.11 三元运算符

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Title</title>

<script type="text/javascript">

//var a=5>3 ? "a=5>3结果为真返回5" : "结果为真返回3"

//document.write(a) //a=5>3结果为真返回5

//var b =prompt("请输入年龄");

//e=b>20 && b<60 ? "可以娶老婆":"不可以娶老婆"

//document.write(e) //输入58,返回可以娶老波,输入61,返回不可以娶老婆

var b =prompt("请输入年龄");

var f =prompt("请输入年薪");

e=b>20 && b<60 || (b>60 && f>120) ? "可以娶老婆":"不可以娶老婆"

document.write(e) //输入58,返回可以娶老波,输入61,年薪190,返回可以娶老婆

</script>

</head>

<body>

</body>

</html>